//package com.fingard.dsp.bank.directbank.ccb04;
//
//import com.fingard.dsp.bank.directbank.bankInterface.IAcceptNotice;
//import com.fingard.generalobj.NoticeReq;
//import com.fingard.generalobj.NoticeResp;
//import com.fingard.io.FileHelper;
//import com.fingard.net.listener.SocketReceiver;
//import com.jxlife.security.SM2Utils;
//import com.jxlife.security.Util;
//
//import java.io.File;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * Created by F on 2017/11/17.
// * 接收客户端的请求
// */
//public class CCB04AcceptNotice extends CCB04Base implements IAcceptNotice {
//    @Override
//    public NoticeResp dealNotice(NoticeReq pNtReq) throws Exception {
//    	NoticeResp resp = new NoticeResp();
//    	String p_req = pNtReq.getReqString();
//    	WriteBankLogLn("接收到请求：" + p_req);
//
//        String data = "";
//        //接收银行请求参数?
//        List<byte[]> list = new ArrayList<byte[]>();
//        try {
//            //本地生成RSA密钥对
//            boolean useLocalSecret = getBankConfig().getValueAsBool("useLocalSecret");
//            WriteBankLogLn("是否读取本地密钥(useLocalSecret):" + useLocalSecret);
//            if (useLocalSecret) {
//                String localPubKeyPath = bankFront.bkTransFolder + bankFront.org + "_pubkey.txt";
//                String localPriKeyPath = bankFront.bkTransFolder + bankFront.org + "_prikey.txt";
//                String pubKeyPlainText;
//                boolean isNotNeedDecrypt = getBankConfig().getValueAsBool("isNotNeedDecrypt");
//                WriteBankLogLn("是否读取本地密钥后不进行解密:" + isNotNeedDecrypt);
//                if (isNotNeedDecrypt) {
//                    WriteBankLogLn("已解密保险公司公钥路径:" + localPubKeyPath);
//                    pubKeyPlainText = FileHelper.readFileText(localPubKeyPath, getCharset());
//                    WriteBankLogLn("已解密保险公司公钥明文内容为:" + pubKeyPlainText);
//                    WriteBankLogLn("已解密保险公司私钥路径:" + localPriKeyPath);
//                    String localPriKeyMsg = FileHelper.readFileText(localPriKeyPath, getCharset());
//                    WriteBankLogLn("已解密保险公司私钥明文内容为:" + localPriKeyMsg);
//                } else {
//                    // 1.保险公司公钥解密
//                    String localPubKeyPath1 = bankFront.bkTransFolder;
//                    WriteBankLogLn("------------------------------------------------");
//                    List<String> pubfileNames = new ArrayList<String>();
//                    File file1 = new File(localPubKeyPath1);
//                    if (file1.isDirectory()) {
//                        WriteBankLogLn("localPubKeyPath1是真实存在的路径");
//                        File[] files = file1.listFiles();
//                        for (int i = 0; i < files.length; i++) {
//                            pubfileNames.add(files[i].getName());
//                        }
//                    }
//                    WriteBankLogLn("localPubKeyPath1路径下的所有文件" + pubfileNames.toString());
//                    File file = new File(localPubKeyPath);
//                    if (file.isFile()) {
//                        WriteBankLogLn(localPubKeyPath + "是一个文件");
//                    }
//                    WriteBankLogLn("------------------------------------------------");
//                    WriteBankLogLn("本机待解密保险公司公钥路径:" + localPubKeyPath);
//                    String localPubKeyMsg = FileHelper.readFileText(localPubKeyPath, getCharset());
//                    WriteBankLogLn("本机待解密保险公司公钥内容:" + localPubKeyMsg);
//                    String localDecryptKey = getBankConfig().getValueAsString("localDecryptKey");
//                    WriteBankLogLn("本机解密国密私钥key值:" + localDecryptKey);
//                    pubKeyPlainText = base64Encoder.encode(SM2Utils.decrypt(Util.hexToByte(localDecryptKey), Util.hexToByte(localPubKeyMsg)));
//                    WriteBankLogLn("使用国密私钥解密后保险公司公钥明文内容为:" + pubKeyPlainText);
//                    String targetPubKeyPath = strtmpFile + bankFront.org + "_pubkey.txt";
//                    WriteBankLogLn("本机解密后保险公司公钥保存路径:" + targetPubKeyPath);
//                    FileHelper.writeFile(targetPubKeyPath, pubKeyPlainText, getCharset());
//                    WriteBankLogLn("本机解密后保险公司公钥保存本机成功...");
//
//                    // 2.保险公司私钥解密
//                    String localPriKeyPath1 = bankFront.bkTransFolder;
//                    WriteBankLogLn("------------------------------------------------");
//                    List<String> prifileNames = new ArrayList<String>();
//                    File file2 = new File(localPriKeyPath1);
//                    if (file2.isDirectory()) {
//                        WriteBankLogLn("localPriKeyPath1是真实存在的路径");
//                        File[] files = file2.listFiles();
//                        for (int i = 0; i < files.length; i++) {
//                            prifileNames.add(files[i].getName());
//                        }
//                    }
//                    WriteBankLogLn("localPriKeyPath1路径下的所有文件" + prifileNames.toString());
//                    File file3 = new File(localPriKeyPath);
//                    if (file3.isFile()) {
//                        WriteBankLogLn(localPriKeyPath + "是一个文件");
//                    }
//                    WriteBankLogLn("------------------------------------------------");
//
//                    WriteBankLogLn("本机待解密保险公司私钥路径:" + localPriKeyPath);
//                    String localPriKeyMsg = FileHelper.readFileText(localPriKeyPath, getCharset());
//                    WriteBankLogLn("本机待解密保险公司私钥内容:" + localPriKeyMsg);
//                    String priKeyPlainText = base64Encoder.encode(SM2Utils.decrypt(Util.hexToByte(localDecryptKey), Util.hexToByte(localPriKeyMsg)));
//                    WriteBankLogLn("使用国密私钥解密后保险公司私钥明文内容为:" + priKeyPlainText);
//                    String targetPriKeyPath = strtmpFile + bankFront.org + "_prikey.txt";
//                    WriteBankLogLn("本机解密后保险公司私钥保存路径:" + targetPriKeyPath);
//                    FileHelper.writeFile(targetPriKeyPath, priKeyPlainText, getCharset());
//                    WriteBankLogLn("本机解密后保险公司私钥保存本机成功...");
//                }
//                list.add("000000".getBytes(getCharset()));
//                list.add(pubKeyPlainText.getBytes(getCharset()));
//                data = base64Encoder.encode(list.get(0)) + pubKeyPlainText;
//            } else {
//                list = transferRsaKeys();
//                data = base64Encoder.encode(list.get(0)) + base64Encoder.encode(list.get(1));
//            }
//        } catch (Exception e) {
//            this.WriteBankLogLn(e);
//        }
//        WriteBankLogLn("响应："+data);
//        resp.respBytes = data.getBytes(pNtReq.reqCharset);
//    	return resp;
//    }
//
//    @Override
//    public void getContentLength(SocketReceiver p_receiver) throws Exception {
//    }
//}